package com.lanju.dao;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.lanju.entity.TodoSomeThing;
@Repository
public class TodoSomeThingDao {
	
    private static final Log log = LogFactory.getLog(TodoSomeThingDao.class);
    @Autowired
   	SessionFactory sessionFactory;
    
    @PersistenceContext(unitName = "financialmarketingUnit")
    private EntityManager entityManager;
    
    public void save(TodoSomeThing entity){
    	try {
			entityManager.persist(entity);
		} catch (Exception e) {
			e.printStackTrace();
		}
    }
    
    public TodoSomeThing update(TodoSomeThing entity){
    	try {
    		entity= entityManager.merge(entity);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return entity;
    }
    
    public void delete(Integer todo_id){
    	try {
			StringBuffer sql = new StringBuffer();
			sql.append("delete from TodoSomeThing where todo_id = "+todo_id);
			entityManager.createQuery(sql.toString()).executeUpdate();
		} catch (Exception e) {
			e.printStackTrace();
		}
    }
    
    public TodoSomeThing getTodoSomeThingById(Integer todo_id){
    	try {
    		return entityManager.find(TodoSomeThing.class, todo_id);
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
    }
    
}
